package com.tuling.designpattern.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 林瑞涛
 * @desc   具体中介者
 * @date 2021年08月10日 19:39
 */
public class ConcreteMediator implements Mediator{
    private List<Colleague> colleagues = new ArrayList<>();

    @Override
    public void register(Colleague colleague) {
        if(!colleagues.contains(colleague)){
            colleagues.add(colleague);
            colleague.setMediator(this);
        }
    }

    @Override
    public void relay(Colleague colleague) {
        for(Colleague col : colleagues){
            if(!col.equals(col)){
                col.receive();
            }
        }
    }
}
